package com.hotel.mapper;

import com.hotel.pojo.Hotel;
import com.hotel.pojo.Room;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoomMapper {
    // 查询所有房间信息
    @Select("select * from room")
    @Results(id = "roomResults", value = {
            @Result(property = "hotelName", column = "hotel_name")
    })
    List<Room> findAllRoom();

    // 添加房间
    @Insert("insert into room(hotel_name, type, price, num) values(#{hotelName}, #{type}, #{price}, #{num})")
    void addRoom(Room room);

    // 查找房间
    @Select("select * from room where hotel_name=#{hotelName} and type=#{type}")
    @ResultMap(value = "roomResults")
    Room findRoomByHotelAndType(Room room);

    @Select("select * from room where hotel_name=#{hotelName}")
    @ResultMap(value = "roomResults")
    List<Room> findRoomByHotel(String hotelName);

    // 更新房间信息
    @Update("update room set price=#{price}, num=#{num} where hotel_name=#{hotelName} and type=#{type}")
    void updateRoom(Room room);

    // 删除房间
    @Delete("delete from room where hotel_name=#{hotelName} and type=#{type}")
    void deleteRoom(Room room);

}
